import { getTokenRequest } from '../api'
import Taro from '@tarojs/taro'

export const LoginWx = () => {
  return new Promise((resolve, reject) => {
    Taro.login({
      success: async function (res) {
        console.log(res, 'res');
        if (res.code) {
          const result = await getTokenRequest({code: res.code})

          resolve(result.data)
        } else {
          reject({code: 999, msg: '登录失败 WX-login success'})
        }
      },
      fail: res => {
        console.log(res, 'fail')

        reject({code: 999, msg: '登录失败 WX-login fail'})
      }
    })
  })
}